const http = require("http")
const cheerio = require("cheerio")

const express = require("express")
const app = express()

const routerParser = require('./router/parser')
app.use('/api', routerParser)

app.get('/', (req, res) => {
    res.send("<h1> hello express</h1>" )
})



app.listen(80, "127.0.0.1", () => {
    console.log("vega-server start at http://127.0.0.1:80")
})






async function fetchX() {


    let ss = await new Promise((resovle, reject) => {
        let req = http.request("http://www.bimiacg4.net", (res) => {
            let truncks = []
            res.on("data", trunk => {
                truncks.push(trunk)
            })
    
            res.on("end", () => {
                let resp = Buffer.concat(truncks).toString("utf-8")
    
                const $ = cheerio.load(resp)
                $('body').html("<h1>hello cheerio</h1>")
                let html = $.html()
                resovle(html)
            });
        })
        req.end()
    })

    console.log(ss)

    return ss

}